﻿@using System.Diagnostics;
@using System.Collections;
@using System.Reflection;
@using System.Runtime.Versioning;
@using Microsoft.AspNetCore.Http
@using NewLife
@using NewLife.Common;
@using NewLife.Reflection;
@using HttpContext = NewLife.Web.HttpContext
@inject IHttpContextAccessor HttpContextAccessor

@{
    //Layout = NewLife.Cube.Setting.Current.Layout;

    ViewBag.Title = "服务器变量列表";
    var httpContext = HttpContextAccessor.HttpContext;
    var req = httpContext.Request;
    // ASP.NET Core中没有ServerVariables的对应实现，需要换一种方式，可以在HttpContext.Request.Headers中获取
}

<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover table-row-bordered table-row-dashed gy-4">
                <tr>
                    <th class="text-dark text-hover-primary text-uppercase fs-3" colspan="6">
                        服务器变量列表
                    </th>
                </tr>
                <tr class="fs-4">
                    <th>名称</th>
                    <th>数值</th>
                </tr>
                @foreach (var kv in req.Headers)
                {
                    var v = kv.Value.ToString();
                    v = v.Replace("\r\n", "</br>");
                    var key = kv.Key;
                    if (key.EqualIgnoreCase("HTTP_COOKIE")) { v = v.Replace(";", "</br>"); }
                    <tr>
                        <td style="max-width:200px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" data-bs-toggle="tooltip" title="@key">@key</td>
                        <td style="max-width:600px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" data-bs-toggle="tooltip" title="@Html.Raw(v)">@Html.Raw(v)</td>
                    </tr>
                }
            </table>
        </div>
    </div>
</div>

<div class="pt-5">
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover table-row-bordered table-row-dashed gy-4">
                    <tr>
                        <th class="text-dark text-hover-primary fs-3" colspan="6">
                            Request变量列表&nbsp;&nbsp;&nbsp;&nbsp;@req.GetType().FullName
                        </th>
                    </tr>
                    <tr class="fs-4">
                        <th>名称</th>
                        <th>数值</th>
                    </tr>
                    @foreach (var pi in req.GetType().GetProperties())
                    {
                        var type = pi.PropertyType;
                        if (pi.GetIndexParameters().Length > 0 || (type != typeof(String)
                        && type != typeof(Uri)
                        && type != typeof(PathString)
                        && type != typeof(HostString)
                        && !typeof(Boolean).IsAssignableFrom(type)
                        && !typeof(String).IsAssignableFrom(type)))
                        {
                            continue;
                        }
                        var v = req.GetValue(pi) + "";
                        v = v.Replace("\r\n", "</br>");
                        <tr>
                            <td style="max-width:200px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" data-bs-toggle="tooltip" title="@pi.Name">@pi.Name</td>
                            <td style="max-width:600px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" data-bs-toggle="tooltip" title="@Html.Raw(v)">@Html.Raw(v)</td>
                        </tr>
                    }
                </table>
            </div>
        </div>
    </div>
</div>

